package com.rgs.se.algorithm.recursive;

import java.util.Scanner;

public class Test2 {
    //查找有序字符串数组中的某个
    static int findMinS(String[] arr,int begin,int end,String targer){
        if(begin>end)
            return -1;
        int mid = (begin+end)/2;
        while(arr[mid].equals("")){
            mid++;
            //防止死循环
            if (mid > end) {
                return -1;
            }
        }
        if(targer.equals(arr[mid])){
            return mid;
        }
        //targer在右侧
        if(arr[mid].compareTo(targer)<0){
            return findMinS(arr,mid+1,end,targer);
        }
        //targer在左侧
        else if (arr[mid].compareTo(targer)>0){
            return findMinS(arr,begin,mid-1,targer);
        }
        else{
            return mid;
        }
    }
    //连续最大子序列
    static int findMaxLength(int[] arr1){
        int slow = 0;
        int fast = 1;
        int len = 0;
        while(fast < arr1.length-1){
            if (arr1[fast] >= arr1[fast-1]){
                fast++;
            }
            if(arr1[fast] < arr1[fast-1]){
                if((fast - slow) > len){
                    len = fast - slow;
                }
                slow = fast;
                fast++;
            }
        }
        return len;
    }
    //求a的n次方
    static int aandn(int a,int n){
        if (a == 0){
            return -1;
        }
        if(n == 0){
            return 1;
        }
        return a*aandn(a,n-1);
    }
    //
    static void aaa(){
        Scanner sc = new Scanner(System.in);
        while(true) {
            System.out.print("请输入一个数字：");
            System.out.println();
            int a = sc.nextInt();
            System.out.println("您输入的数字为：" + a);
            if(a == 0){
                break;
            }
        }
    }
    public static void main(String[] args) {
//        String[] arr = {"ac","ad","","cd","","dd","el","","gg","",""};
//        int[] arr1 = {1,9,2,5,7,3,4,6,8,0};
//        System.out.println(findMinS(arr,0,9,"ddd"));
//        System.out.println(findMaxLength(arr1));
//
        aaa();
    }
}
